# 将字典结构写入文件，并从文件中读取出来，不使用json库
import os
import ast

def save_dict_to_file(dict, filename):
    with open(filename, 'w') as file:
        file.write(f'{dict}')

def load_dict_from_file(filename):
    dictionary = {}
    if os.path.exists(filename):
        with open(filename, 'r') as file:
            data = file.read()
            result = ast.literal_eval(data)
            return result

    return dictionary

if __name__ == "__main__":
    data = {'name': 'Tom', 'age': 20, 'gender': 1}
    data[65535] = 'nima'
    filename = 'data.txt'
    save_dict_to_file({"name", 35, 42}, filename)
    result = load_dict_from_file(filename)
    print(f"result = {result}")